const Service = require('egg').Service;
class WxwService extends Service {
    async menuinfo(id) {
        const sql = `SELECT * FROM  user inner join cook1user on user.id=cook1user.userid inner join cook on cook.id=cook1user.cookid where cook.id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async userinfo(id) {
        const sql = `SELECT user.id as userid,username,cook.id as cookid,img,title,浏览次数 FROM  user inner join cook1user on user.id=cook1user.userid inner join cook on cook.id=cook1user.cookid where user.id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wreviewinfo(id) {
        const sql = `select commentid,userid,neirong,pushtime,good,username,touxiang from comment inner join comment1user on comment.id=comment1user.commentid inner join user on user.id=comment1user.userid where comment.id in (select commentid from cook1comment inner join cook on cook.id=cook1comment.cookid where cook.id=${id})`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async altercommentgood(id, move) {
        const sql = `UPDATE comment SET good=good${move}1 WHERE id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wstorecook(cookid, userid) {
        const sql = `INSERT INTO good1cook (cookid,userid) VALUES (${cookid},${userid})`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wcookopus(id) {
        const sql = `select userid,img,tip,pushtime,opusid,username,touxiang,say from opus inner join opus1user on opus.id=opusid inner join user on userid=user.id 
        where opus.id in (select opusid from opus1cook where cookid = ${id})`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async waddopus(img, title, tip, pushtime) {
        const sql = `INSERT INTO opus (img,title,tip,pushtime) VALUES ('${img}', '${title}', '${tip}','${pushtime}')`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wclassinfo() {
        const sql = `select id,classer from caipu order by soucang limit 8`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wrelevant(id) {
        const sql = `select id,title from cook where class=(select class from cook where id=${id})`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wshoucanginfo(id) {
        const sql = `select count(id) as count from good1cook where cookid=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async wifstore(userid, cookid) {
        const sql = `select * from good1cook where cookid=${cookid} and userid=${userid}`
        const data = await this.app.mysql.query(sql);
        return data;
    }

    async wuserinfo(id) {
        const sql = `select * from user where id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async walteruser(id, touxiang) {
        const sql = `UPDATE user SET touxiang="${touxiang}" WHERE id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async walteruseremail(id, email, pwd) {
        const sql = `UPDATE user SET email="${email}",pwd="${pwd}" WHERE id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }
    async walteruserinfo(id, username, say, address, sex) {
        const sql = `UPDATE user SET sex="${sex}",username="${username}",address="${address}",say="${say}" WHERE id=${id}`
        const data = await this.app.mysql.query(sql);
        return data;
    }


    async wcookinfo() {
        const sql = `select * from cook inner join cook1user on cook.id=cook1user.cookid inner join user on user.id=cook1user.userid`
        const data = await this.app.mysql.query(sql);
        return data;
    }
}
module.exports = WxwService;